define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'coupon/coupon/index' + location.search,
                    add_url: 'coupon/coupon/add',
                    edit_url: 'coupon/coupon/edit',
                    del_url: 'coupon/coupon/del',
                    multi_url: 'coupon/coupon/multi',
                    import_url: 'coupon/coupon/import',
                    table: 'coupon',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'coupon_type', title: __('Coupon_type')},
                        {field: 'price_type', title: __('Price_type')},
                        {field: 'price', title: __('Price')},
                        {field: 'min_consume', title: __('Min_consume')},
                        {field: 'receive_type', title: __('Receive_type')},
                        {field: 'receive_start_time', title: __('Receive_start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'receive_end_time', title: __('Receive_end_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'validity_period_type', title: __('Validity_period_type')},
                        {field: 'validity_days', title: __('Validity_days')},
                        {field: 'validity_start_time', title: __('Validity_start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'validity_end_time', title: __('Validity_end_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'coupon_count', title: __('Coupon_count')},
                        {field: 'discount_stack_type', title: __('Discount_stack_type')},
                        {field: 'receive_coupon_count', title: __('Receive_coupon_count')},
                        {field: 'user_idss', title: __('User_idss')},
                        {field: 'status', title: __('Status'), searchList: {"11":__('Status 11')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'delete_time', title: __('Delete_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
